import { getCookie } from '~/utils/cookie'

export default function ({ $axios, redirect }) {
  // 请求拦截
  $axios.onRequest(config => {
    const wlist = [
      '/user/v1/login',
      '/user/v1/account'
    ]
    if (wlist.indexOf(config.url) === -1) {
      let token = String(getCookie('token'))
      config.headers = {
        'Authorization': `Bearer ${token}`
      }
    }
    if (config.url === '/user/v1/account' && config.method === 'put') {
      let token = String(getCookie('token'))
      config.headers = {
        'Authorization':`Bearer ${token}`
      }
    }
  })
}
